#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <pthread.h>
#include <string.h>

void *thread_function(void *arg);
char  message[]="THREAD_TEST";


int main (int arc,char* argv[])
{

	int res;
	pthread_t a_thread;
	void *thread_result;
	res=pthread_create(&a_thread,NULL,thread_function,(void*)message);
	if(res != 0){

		perror("create thread fail");
		exit(EXIT_FAILURE);
	}

	printf("waiting thread over");
	res=pthread_join(a_thread,&thread_result);
	if(res != 0){

		perror("waiting thread failed");

		exit(EXIT_FAILURE);
	}

	printf("thread over return value: %s\n",(char*)thread_result);

	printf("message value is %s\n",message);
	exit(EXIT_SUCCESS);


	return 0;
}

void *thread_function(void* arg)
{

	printf("thread now is running ,arg is :%s\n",(char*)arg);
	sleep(3);
	strcpy(message,"threadChanged");
	pthread_exit("thread is ended");
	
}